package testes.usuario;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JPasswordField;
import javax.swing.JLabel;

import modelo.usuario.Usuario;
import javax.swing.JProgressBar;

public class TesteInserirUsuario extends JFrame {

	private JPanel contentPane;
	public JTextField textField;
	public JPasswordField passwordField;
	JButton btnNewButton_1;
	JButton btnUpdate;
	JButton btnInsert;
	//	int selected;
	Usuario usuario;
	JProgressBar barraProgresso;
	JLabel labelProgresso;
	Progresso prog;
	/**
	 * Create the frame.
	 */
	public TesteInserirUsuario() {

		setVisible(true);
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		barraProgresso = new JProgressBar();
		labelProgresso = new JLabel("New label");
		//		barraProgresso.setIndeterminate(true);
		prog = new Progresso(this,labelProgresso, barraProgresso);
		prog.addPropertyChangeListener(new PropertyChangeListener() {

			@Override
			public void propertyChange(PropertyChangeEvent evt) {
				if ("progress".equals(evt.getPropertyName())) {
					barraProgresso.setValue((Integer)evt.getNewValue());
				}

			}
		});
		prog.execute();
		
		btnInsert = new JButton("inserir");
		btnInsert.addActionListener(new CrudUsuarioControle(this));
		textField = new JTextField();
		textField.setColumns(10);

		passwordField = new JPasswordField();

		JLabel lblUsurio = new JLabel("Usu\u00E1rio");

		JLabel lblSenha = new JLabel("Senha");

		btnNewButton_1 = new JButton("listar");
		btnNewButton_1.addActionListener(new CrudUsuarioControle(this));




		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
				gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
						.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_contentPane.createSequentialGroup()
										.addGap(87)
										.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
												.addComponent(lblUsurio)
												.addComponent(lblSenha, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE))
												.addGap(18)
												.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
														.addGroup(gl_contentPane.createSequentialGroup()
																.addComponent(btnInsert)
																.addPreferredGap(ComponentPlacement.RELATED)
																.addComponent(btnNewButton_1))
																.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
																		.addComponent(textField, Alignment.LEADING)
																		.addComponent(passwordField, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 118, GroupLayout.PREFERRED_SIZE))))
																		.addComponent(barraProgresso, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
																		.addGroup(gl_contentPane.createSequentialGroup()
																				.addGap(55)
																				.addComponent(labelProgresso)))
																				.addContainerGap(171, Short.MAX_VALUE))
				);
		gl_contentPane.setVerticalGroup(
				gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
						.addGap(31)
						.addComponent(labelProgresso)
						.addPreferredGap(ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
						.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblUsurio))
								.addPreferredGap(ComponentPlacement.RELATED)
								.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
										.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
										.addComponent(lblSenha))
										.addGap(18)
										.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
												.addComponent(btnInsert)
												.addComponent(btnNewButton_1))
												.addGap(48)
												.addComponent(barraProgresso, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
												.addGap(27))
				);
		contentPane.setLayout(gl_contentPane);
	}

	public TesteInserirUsuario(Usuario usuario, TesteListarUsuario listar) {
		setVisible(true);
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		this.usuario = usuario;
		btnUpdate = new JButton("atualizar");
		btnUpdate.addActionListener(new CrudUsuarioControle(this, listar));
		textField = new JTextField(usuario.getNomeUsuario());
		textField.setColumns(10);

		passwordField = new JPasswordField(usuario.getSenha());

		JLabel lblUsurio = new JLabel("Usu\u00E1rio");

		JLabel lblSenha = new JLabel("Senha");

		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
				gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
						.addGap(87)
						.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
								.addComponent(lblUsurio)
								.addComponent(lblSenha, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE))
								.addGap(18)
								.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
										.addGroup(gl_contentPane.createSequentialGroup()
												.addComponent(btnUpdate)
												.addPreferredGap(ComponentPlacement.RELATED)
												.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
														.addComponent(textField, Alignment.LEADING)
														.addComponent(passwordField, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 118, GroupLayout.PREFERRED_SIZE))))));
		gl_contentPane.setVerticalGroup(
				gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
						.addContainerGap(86, Short.MAX_VALUE)
						.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblUsurio))
								.addPreferredGap(ComponentPlacement.RELATED)
								.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
										.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
										.addComponent(lblSenha))
										.addGap(18)
										.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
												.addComponent(btnUpdate)
												.addGap(89))
						));
		contentPane.setLayout(gl_contentPane);
	}
}
